<template>
	<view class="app">
		<view class="uni-form-item uni-column">
			<view class="title">邮箱：</view>
			<input class="uni-input" focus placeholder="请输入你得邮箱" v-model="email" />
			
		</view>
		
		<view class="uni-form-item uni-column">
			<view class="title">密码：</view>
			<input class="uni-input" password v-model="pass" type="text" placeholder="请输入你得密码" />
		</view>
		
		<button type="primary" class="btn" @click="handleLogin">登录</button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				email: "a@qq.com",
				pass: "123456",
				tk: "",
				data: []
			}
		},
		methods: {
			async handleLogin() {
				let data = {
					email: this.email,
					password: this.pass,
				}
				await uni.request({
					url:this.$BASE_URL + "login",
					method:"POST",
					data,
					success(res) {
						console.log(res)
						if(res.data.code === 200){
							this.tk = res.data.user.tokens
							this.data = res.data.user
							uni.setStorage({
								key: "tokens",
								data: this.tk,
							})
							uni.setStorage({
								key: "data",
								data: this.data,
							})
							uni.switchTab({
								url: `/pages/mine/mine`
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
	.app{
		width: 100%;
		height: 100vh;
		background: rgb(242, 242, 242);
		padding-top: 50rpx;
		.uni-form-item{
			display: flex;
			flex-wrap: wrap;
			height: 80rpx;
			background: white;
			margin-top: 20rpx;
			line-height: 80rpx;
			padding: 0 20rpx;
			.uni-input{
				width: 85%;
				height: 80rpx;
				
			}
		}
		.btn{
			margin: 30rpx;	
		}
	}

</style>
